package com.source.baseData.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.source.baseData.entity.SlaughterHouse;
import com.source.baseData.entity.SlaughterHouseRepair;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.source.baseData.vo.SlaughterHouseRepairVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author IceBerg777
 * @since 2021-03-21
 */
public interface SlaughterHouseRepairMapper extends BaseMapper<SlaughterHouseRepair> {

    String SELECT = "SELECT shr.*, sh.slaughterHouseName houseName, su.`name` `name`, mobile\n" +
            "FROM slaughter_house_repair shr, slaughter_house sh, sys_user su  \n" +
            "WHERE shr.houseId = sh.slaughterHouseId AND shr.userId = su.userId " +
            "AND shr.isDelete = 0 ";

    @Select(SELECT)
    IPage<SlaughterHouseRepairVo> findAll(Page<SlaughterHouseRepairVo> page);

    @Select(SELECT + "AND houseId = #{houseId} ")
    IPage<SlaughterHouseRepairVo> findByHouseId(String houseId, Page<SlaughterHouseRepairVo> page);

    @Select(SELECT + "AND houseId = #{houseId} ")
    List<SlaughterHouseRepairVo> findByHouseId(String houseId);

    @Select(SELECT + "AND sh.slaughterHouseName LIKE #{keyWord}")
    List<SlaughterHouseRepairVo> findByKeyWord(String keyWord);

    @Select("SELECT  DISTINCT shr.houseId, sh.slaughterHouseName houseName\n" +
            "            FROM slaughter_house_repair shr, slaughter_house sh\n" +
            "            WHERE shr.houseId = sh.slaughterHouseId AND shr.isDelete = 0 ")
    List<SlaughterHouseRepairVo> findDistinct();

    @Select("SELECT sh.* FROM slaughter_house sh WHERE sh.slaughterHouseId NOT IN (SELECT houseId FROM slaughter_house_repair " +
            "WHERE shr.isDelete = 0 ) ")
    List<SlaughterHouse> findUnAdded();
}
